home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 4607 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.4 KB  |  120 lines

  1. Path: easy.in-chemnitz.de!mkmk!floh
  2. From: floh@mkmk.in-chemnitz.de (Andre Weissflog)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: simple K&R ANSI-C examples won't compile under SAS/C
  5. Message-ID: <inOay*mG0@mkmk.in-chemnitz.de>
  6. Date: Fri, 01 Mar 1996 20:57:54 CET
  7. Reply-To: floh@mkmk.in-chemnitz.de
  8. References: <68771782@0humpty.tomate.tng.oche.de>
  9. Distribution: world
  10. Organization: private uucp site
  11. X-Newsreader: Arn V 1.04
  12.  
  13. In article <68771782@0humpty.tomate.tng.oche.de>, Andreas Mixich writes:
  14.  
  15. >     Hi,
  16. > this little example form the 'Kernighan&Ritchie' won't compile:
  17. > #include <stdio.h>
  18. > #include <clib/alib_stdio_protos.h>
  19. > main()
  20. > {
  21. >     int c;
  22. >      while((c = GetChar()) !=EOF)
  23. >       PutChar(c);
  24. > }
  25. > Yes, *you* laugh now, but for me this is really strange.
  26. > I get an error #72 in alib_stdio_protos.h; conflict with previous declaration,
  27. > see file stdio.h.
  28.  
  29. Easy. In <stdio.h> e.g. the printf() prototype is defined as
  30.  
  31.     extern int printf(const char *, ...);
  32.  
  33. in <clib/alib_stdio_protos.h> as
  34.  
  35.     LONG printf( STRPTR fmt, ... );
  36.  
  37.  
  38. The same function is declared twice with different
  39. parameter types, thus the compiler error.
  40.  
  41. Now to the real problems:
  42.  
  43. 1st) The prototypes in alib_stdio_protos.h are Amiga-ized
  44.      replacement functions for some of ANSI-C's stdio
  45.      functions. You can either use the stdio functions
  46.      that came with your compiler, *or* the ones
  47.      in amiga.lib. But not both in the same code.
  48.  
  49.      The ANSI stdio replacement functions in amiga.lib are
  50.      IMHO only of limited use for the following reasons
  51.      (amongst others):
  52.  
  53.      - formatted string output goes through 
  54.        exec.library/RawDoFmt(), which is not
  55.        fully compatible to and not as powerful as
  56.        ANSI's formatting
  57.      - no cleanup at exit() for open file handles
  58.      - amiga.lib stdio file handles can't be mixed
  59.        with the file handles of your compilers
  60.        stdio functions
  61.      - extra care must be taken to link amiga.lib before
  62.        c.lib
  63.  
  64.      The only advantage is that your executables can
  65.      become drastically smaller, since you don't need
  66.      the compilers IO startup/cleanup code, and
  67.      there's much less additional code linked
  68.      to your program.
  69.  
  70.      *BUT* in that case you're better going with
  71.      dos.library's "look-a-likes" (Printf() for instance,
  72.      note the 'P').
  73.  
  74. 2nd) GetChar() and PutChar() are not ANSI C functions,
  75.      the correct names are getchar() and putchar().
  76.      Thus your program should look like:
  77.  
  78.      #include <stdio.h>
  79.  
  80.      int main(void)
  81.      {
  82.         int c;
  83.         while((c = getchar()) != EOF) putchar(c);
  84.         return 0;
  85.      }
  86.  
  87. > Now, I have read the guide on this error, but if I leave out the
  88. > alib_stdio_protos.h, this will cause the error, no Prototype for function
  89. > getchar() (or so).
  90.  
  91. Nope :-)
  92. If you leave out alib_stdio_protos.h, the compiler will give
  93. you a warning that there's no prototype for GetChar(). But
  94. the correct name would be getchar() (and that one is defined
  95. in stdio.h).
  96.  
  97. > Also, if I do a c = GetChar(void) (as synopsis description in sclib.guide
  98. > shows) the error still ocuures.
  99. GetChar() != getchar()
  100.  
  101. C is always case sensitiv.
  102.  
  103. Bye,
  104. -Floh.
  105.  
  106. ====//=== Andre Weissflog <floh@mkmk.in-chemnitz.de> =======
  107. ...// Sep'95: Return Of The Living Death...................
  108. \\// 90% of everything is crap (Sturgeon's Law)...........
  109. =\\===============================================Amiga!=
  110.  
  111.